//我的订单
let express = require('express');
let path = require('path');
//引入自定义模块
let user = require('../model/user');
let order = require('../model/order');

var router = express.Router();


router.get('/',function(req,res,next){
    res.sendStatus(404);
});
/**
 *登录验证功能
 */
router.post('/',function (req,res,next){
    let userID = req.body.userID;
    let token = req.body.token;
    if(user.checkToken(userID,token) == false){
        res.send({myorderInfoStatus:2});
    }
    else {
        order.search(userID,function (result){
            if(result.length === 0){
                res.send({myorderInfoStatus:1});
            }
            else {
                arr = [];
                for(i=0;i<result.length;i++){
                    arr[i]= parseInt(result[i].orderID);
                }
                re = {
                    myorderInfoStatus:0,
                    myorderList: arr
                }
                res.send(re);
            }
        })
    }
})
module.exports = router;